propsage.namespace("prestige.form");

prestige.form.update = function($) {
    function initComponents() {  
        if (mode == 2) {
            var rejectDialog = '<div id="rejectDialog" title="Reason for rejecting">'
                + '<form id="rejectForm" method="POST">'
                    + '<textarea id="rejectReason" name="rejectReason" rows="5" cols="30"></textarea>'
                    + '<input type="hidden" name="action" value="reject" />'
                + '</form>'
            + '</div>';
            $('body').append(rejectDialog);
        
            $('#rejectDialog').dialog({
                resizable: false,
                draggable: false,
                autoOpen: false,
                width: 'auto',
                height: 'auto',
                modal: true,
                buttons: {
                    'OK': onRejectDialogOK,
                    'Cancel': onDialogCancel
                }
            });
        }
    }
    
    function initEventHandlers() {
        if (mode == 2) {
            $('#btnReject').click(onBtnRejectClick);
        }
    }
    
    function onDialogCancel() {
        $(this).dialog("close");
    }
    
    function onRejectDialogOK() {        
        if ($('#rejectReason').val() == '') {
            window.alert('You must enter a reason for rejecting');
        } else {        
            $('#rejectForm').submit();
        
            $(this).dialog("close");
        }
    }
    
    function onBtnRejectClick(event) {
        event.preventDefault();
        
        $('#rejectDialog').dialog("open");
    }
    
    $(document).ready(function() {    
        initComponents(); 
        initEventHandlers();
    });
    
    /** Public Methods **/
    return {
    // nothing here
    }
    
}(jQuery);